#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 1e6 + 10;

int n;
struct Seg{
    int a, b;
}seg[N];
vector<int> nums;
int p[N];

int f(int x){
    return lower_bound(nums.begin(), nums.end(), x) - nums.begin();
}

int find(int x){
    if(x != p[x]){
        p[x] = find(p[x]);
    }
    return p[x];
}


int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;

    int ta, tb;
    for(int i = 1; i <= n; i ++){
        cin >> ta >> tb;
        seg[i].a = ta, seg[i].b = tb;
        nums.push_back(ta);
        nums.push_back(tb);
    }
    nums.push_back(1);

    sort(nums.begin(), nums.end());
    nums.erase(unique(nums.begin(), nums.end()), nums.end());

    for(int i = 1; i < N; i ++) p[i] = i;
    for(int i = 1; i <= n; i ++){
        int a = f(seg[i].a), b = f(seg[i].b);
//        cout << "seg: " << seg[i].a << " a: " << a << '\n'; 
        int fa = find(a) ,fb = find(b);

        if(fa != fb){
            p[fb] = fa;
        }
    }


    for(int i = nums.size() - 1; i >= 0; i --){
        // cout << "nums: " << nums[i] << '\n';
        if(find(f(nums[i])) == find(f(1))){
            cout << nums[i] << '\n';
            exit(0);
        }
    }

    return 0;
}